//
//  WecomeViewController.swift
//  我的微博
//
//  Created by 吴加将 on 15/9/9.
//  Copyright © 2015年 吴加将. All rights reserved.
//

import UIKit

class WecomeViewController: UIViewController {
    /// 头像底部约束
    private var iconBottomCons: NSLayoutConstraint?

    override func loadView() {
        view=UIImageView(image: UIImage(named: "ad_background"))
    }
    
    
    
    override func viewDidLoad() {
        super.viewDidLoad()
        setUpUI()
    }
//    override func viewDidAppear(animated: Bool) {
//        super.viewDidAppear(animated)
//        setAnimit()
//    }
    override func viewDidAppear(animated: Bool) {
        super.viewDidAppear(animated)
        
        iconBottomCons?.constant = UIScreen.mainScreen().bounds.height - 240
        setAnimit()
 
    }
    //MARK: -设置动画
    private func setAnimit(){
//        iconBottomCons?.constant=UIScreen.mainScreen().bounds.height-240

        UIView.animateWithDuration(1.2, delay: 0, usingSpringWithDamping: 0.8, initialSpringVelocity: 10.0, options: UIViewAnimationOptions(rawValue: 0), animations: { () -> Void in
        self.view.layoutIfNeeded()
        }, completion: nil)
        }
    private func setUpUI(){
    view.addSubview(iconview)
    view.addSubview(label)
    self.label.text="欢迎归来"
        //设置frame
        iconview.translatesAutoresizingMaskIntoConstraints=false
        view.addConstraint(NSLayoutConstraint(item: view, attribute: NSLayoutAttribute.Bottom, relatedBy: NSLayoutRelation.Equal, toItem: iconview, attribute: NSLayoutAttribute.Bottom, multiplier: 1.0, constant: 160))
    view.addConstraint(NSLayoutConstraint(item: iconview, attribute: NSLayoutAttribute.CenterX, relatedBy: NSLayoutRelation.Equal, toItem: view, attribute: NSLayoutAttribute.CenterX, multiplier: 1.0, constant: 0))
        iconBottomCons = view.constraints.first

        label.translatesAutoresizingMaskIntoConstraints=false
    view.addConstraint(NSLayoutConstraint(item: label, attribute: NSLayoutAttribute.Top, relatedBy: NSLayoutRelation.Equal, toItem: iconview, attribute: NSLayoutAttribute.Bottom, multiplier: 1.0, constant: 20))
    view.addConstraint(NSLayoutConstraint(item: label, attribute: NSLayoutAttribute.CenterX, relatedBy: NSLayoutRelation.Equal, toItem: iconview, attribute: NSLayoutAttribute.CenterX, multiplier: 1.0, constant: 0))
        
    }
    
    
    
    //懒加载控件
    lazy var iconview : UIImageView = {
        let iv = UIImageView(image: UIImage(named: "avatar_default_big"))
        iv.layer.masksToBounds=true
        iv.layer.cornerRadius=45
        return iv
}()
    lazy var label=UILabel()
    
}